using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-20
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 设备管理表
    /// </summary>
    [Verify]
    [Route("device/deviceinformation")]
    [ApiExplorerSettings(GroupName = "business")]
    public class DeviceInformationController : BaseController
    {
        /// <summary>
        /// 设备管理表接口
        /// </summary>
        private readonly IDeviceInformationService _DeviceInformationService;

        public DeviceInformationController(IDeviceInformationService DeviceInformationService)
        {
            _DeviceInformationService = DeviceInformationService;
        }

        /// <summary>
        /// 查询设备管理表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "device:deviceinformation:list")]
        public IActionResult QueryDeviceInformation([FromQuery] DeviceInformationQueryDto parm)
        {
            var response = _DeviceInformationService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询设备管理表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "device:deviceinformation:query")]
        public IActionResult GetDeviceInformation(int Id)
        {
            var response = _DeviceInformationService.GetInfo(Id);

            var info = response.Adapt<DeviceInformationDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加设备管理表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "device:deviceinformation:add")]
        [Log(Title = "设备管理表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddDeviceInformation([FromBody] DeviceInformationDto parm)
        {
            var modal = parm.Adapt<DeviceInformation>().ToCreate(HttpContext);

            var response = _DeviceInformationService.AddDeviceInformation(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新设备管理表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "device:deviceinformation:edit")]
        [Log(Title = "设备管理表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateDeviceInformation([FromBody] DeviceInformationDto parm)
        {
            var modal = parm.Adapt<DeviceInformation>().ToUpdate(HttpContext);
            var response = _DeviceInformationService.UpdateDeviceInformation(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除设备管理表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "device:deviceinformation:delete")]
        [Log(Title = "设备管理表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteDeviceInformation([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_DeviceInformationService.Delete(idArr));
        }
    }
}